let myHeading = document.querySelector('h1'); // 声明变量，选择h1对象
myHeading.textContent = 'HelloWorld';// 将文本内容修改为目标文本

// 点击图片切换为另一张，就是获取并修改了图片路径
let myImage = document.querySelector('img');
myImage.onclick = function () {
    let mySrc = myImage.getAttribute('src');
    if (mySrc === 'images/1.jpg') {
        myImage.setAttribute('src', 'images/2.jpg');
    }else {
        myImage.setAttribute('src', 'images/1.jpg');
    }
}

let myButton = document.querySelector('button');

function setUserName() {
    let myName = prompt('请输入你的名字：');
    if (!myName) {
        setUserName()
    }else {
        localStorage.setItem('name', myName);
        myHeading.textContent = 'Google酷毙啦，' + myName;
    }
}

if (!localStorage.getItem('name')) {
    setUserName()
} else {
    let storedName = localStorage.getItem('name');
    myHeading.textContent = 'Google酷毙啦，' + storedName;
}

myButton.onclick = function () {
    setUserName();
}